// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router';
import file from '../components/pages/file.vue';
import Login from '../components/pages/Login.vue';
import Loginview from '../components/pages/LoginView.vue';



const router = createRouter({
    history: createWebHistory(),
    routes:[
    {
        path: '/',
        name: 'Login',
        //component: Loginview,
        component: file,
        meta: { requiresAuth: false }
    },
    {
        path: '/file',
        name: 'file',
        component: file,
        meta: { requiresAuth: true },
    }]
});

router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token')
    if (to.meta.requiresAuth && !token) {
      next('/login')
    } else {
      next()
    }
  })

export default router;